package com.shure.modules.docs.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shure.common.query.condition.Condition;
import com.shure.modules.docs.entity.Prompts;
import com.shure.modules.docs.query.PromptsQuery;
import com.shure.modules.docs.service.PromptsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prompt")
public class PromptController {

    private final PromptsService promptService;

    public PromptController(PromptsService promptService) {
        this.promptService = promptService;
    }

    // 新增提示词
    @PostMapping
    public ResponseEntity create(@RequestBody Prompts prompt) {
        boolean b = promptService.save(prompt);
        return ResponseEntity.ok(b);
    }

    // 查询提示词列表
    @GetMapping("list")
    public ResponseEntity<List<Prompts>> list(PromptsQuery query) {
        LambdaQueryWrapper<Prompts> wrapper = Condition.getLambdaQueryWrapper1(query);
        wrapper.orderByDesc(Prompts::getUpdateAt);
        return ResponseEntity.ok(promptService.list(wrapper));
    }

    // 查询提示词
    @GetMapping("/{id}")
    public ResponseEntity<Prompts> getById(@PathVariable("id") Long id) {
        Prompts prompt = promptService.getById(id);
        return ResponseEntity.ok(prompt);
    }

    // 更新提示词
    @PutMapping("/{id}")
    public ResponseEntity update(@PathVariable("id") Long id, @RequestBody Prompts prompt) {
        prompt.setId(id);
        return ResponseEntity.ok(promptService.updateById(prompt));
    }

    // 删除提示词
    @DeleteMapping("/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
        promptService.removeById(id);
        return ResponseEntity.noContent().build();
    }
}
